home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Games of Daze
/
Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso
/
x2ftp
/
msdos
/
libs
/
knowhow4
/
pcxstrm.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-10
|
1KB
|
50 lines
#include <assert.h>
#include <mem.h>
#include "pcxstrm.h"
// #define NDEBUG 1
pcxstream::pcxstream(FILE * f): pos(0), file(f)
{
buffer = new char[BUFFER_LENGTH];
assert(buffer);
fread(buffer, 1, BUFFER_LENGTH, file);
}
////////////////////
void pcxstream::read(unsigned char * dest, int n)
{
if (pos==BUFFER_LENGTH)
{
fread(buffer, 1, BUFFER_LENGTH, file);
pos=0;
}
int n_from_buf;
n_from_buf = pos + n < BUFFER_LENGTH ? n : BUFFER_LENGTH - pos;
n -= n_from_buf;
if(n_from_buf)
{
memcpy(dest, buffer + pos, n_from_buf);
pos += n_from_buf;
}
while(n > 0)
{
pos = 0;
fread(buffer, 1, BUFFER_LENGTH, file);
n_from_buf = n < BUFFER_LENGTH ? n : BUFFER_LENGTH;
n -= n_from_buf;
if(n_from_buf)
{
memcpy(dest, buffer + pos, n_from_buf);
pos += n_from_buf;
}
}
}
////////////////////////
pcxstream::~pcxstream()
{
delete buffer;
}
////////////////////////